﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract DokumentPlacanje typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class DokumentPlacanjeDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<DokumentPlacanjeDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.DokumentPlacanje _currentDokumentPlacanje = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxDokumentPlacanjeDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxDokumentPlacanjeErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxDokumentPlacanjeBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDDokument property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDDokumentDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDNacinPlacanja property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDNacinPlacanjaDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Uplaceno property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxUplacenoDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Datum property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDatumDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.Dokument> _IDDokumentList;
		
		/// <summary> 
		/// The list of selectable Dokument
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.Dokument> IDDokumentList
		{
			get {return this._IDDokumentList;}
			set 
			{
				this._IDDokumentList = value;
				this.uxIDDokumentDataGridViewColumn.DataSource = null;
				this.uxIDDokumentDataGridViewColumn.DataSource = this._IDDokumentList;
			}
		}
		
		private bool _allowNewItemInIDDokumentList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of Dokument
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDDokumentList
		{
			get { return _allowNewItemInIDDokumentList;}
			set
			{
				this._allowNewItemInIDDokumentList = value;
				this.uxIDDokumentDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.NacinPlacanja> _IDNacinPlacanjaList;
		
		/// <summary> 
		/// The list of selectable NacinPlacanja
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.NacinPlacanja> IDNacinPlacanjaList
		{
			get {return this._IDNacinPlacanjaList;}
			set 
			{
				this._IDNacinPlacanjaList = value;
				this.uxIDNacinPlacanjaDataGridViewColumn.DataSource = null;
				this.uxIDNacinPlacanjaDataGridViewColumn.DataSource = this._IDNacinPlacanjaList;
			}
		}
		
		private bool _allowNewItemInIDNacinPlacanjaList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of NacinPlacanja
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDNacinPlacanjaList
		{
			get { return _allowNewItemInIDNacinPlacanjaList;}
			set
			{
				this._allowNewItemInIDNacinPlacanjaList = value;
				this.uxIDNacinPlacanjaDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.DokumentPlacanje> _DokumentPlacanjeList;
				
		/// <summary> 
		/// The list of DokumentPlacanje to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.DokumentPlacanje> DokumentPlacanjeList
		{
			get {return this._DokumentPlacanjeList;}
			set
			{
				this._DokumentPlacanjeList = value;
				this.uxDokumentPlacanjeBindingSource.DataSource = null;
				this.uxDokumentPlacanjeBindingSource.DataSource = value;
				this.uxDokumentPlacanjeDataGridView.DataSource = null;
				this.uxDokumentPlacanjeDataGridView.DataSource = this.uxDokumentPlacanjeBindingSource;				
				//this.uxDokumentPlacanjeBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxDokumentPlacanjeBindingSource_ListChanged);
				this.uxDokumentPlacanjeBindingSource.CurrentItemChanged += new System.EventHandler(OnDokumentPlacanjeBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnDokumentPlacanjeBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentDokumentPlacanje = uxDokumentPlacanjeBindingSource.Current as Entities.DokumentPlacanje;
			
			if (_currentDokumentPlacanje != null)
			{
				_currentDokumentPlacanje.Validate();
			}
			//_DokumentPlacanje.Validate();
			OnCurrentEntityChanged();
		}

		//void uxDokumentPlacanjeBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.DokumentPlacanje"/> instance.
		/// </summary>
		public Entities.DokumentPlacanje SelectedDokumentPlacanje
		{
			get {return this._currentDokumentPlacanje;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxDokumentPlacanjeDataGridView.VirtualMode;}
			set
			{
				this.uxDokumentPlacanjeDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxDokumentPlacanjeDataGridView.AllowUserToAddRows;}
			set {this.uxDokumentPlacanjeDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxDokumentPlacanjeDataGridView.AllowUserToDeleteRows;}
			set {this.uxDokumentPlacanjeDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxDokumentPlacanjeDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxDokumentPlacanjeDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="DokumentPlacanjeDataGridViewBase"/> class.
		/// </summary>
		public DokumentPlacanjeDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxDokumentPlacanjeDataGridView = new System.Windows.Forms.DataGridView();
			this.uxDokumentPlacanjeBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxDokumentPlacanjeErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDDokumentDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxIDNacinPlacanjaDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxUplacenoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDatumDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			//this.uxIDDokumentBindingSource = new DokumentBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentBindingSource)).BeginInit();
			//this.uxIDNacinPlacanjaBindingSource = new NacinPlacanjaBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDNacinPlacanjaBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentPlacanjeDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentPlacanjeBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentPlacanjeErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxDokumentPlacanjeErrorProvider
			// 
			this.uxDokumentPlacanjeErrorProvider.ContainerControl = this;
			this.uxDokumentPlacanjeErrorProvider.DataSource = this.uxDokumentPlacanjeBindingSource;						
			// 
			// uxDokumentPlacanjeDataGridView
			// 
			this.uxDokumentPlacanjeDataGridView.AutoGenerateColumns = false;
			this.uxDokumentPlacanjeDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxDokumentPlacanjeDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDataGridViewColumn,
		this.uxIDDokumentDataGridViewColumn,
		this.uxIDNacinPlacanjaDataGridViewColumn,
		this.uxUplacenoDataGridViewColumn,
		this.uxDatumDataGridViewColumn			});
			this.uxDokumentPlacanjeDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxDokumentPlacanjeDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxDokumentPlacanjeDataGridView.Name = "uxDokumentPlacanjeDataGridView";
			this.uxDokumentPlacanjeDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxDokumentPlacanjeDataGridView.TabIndex = 0;	
			this.uxDokumentPlacanjeDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxDokumentPlacanjeDataGridView.EnableHeadersVisualStyles = false;
			this.uxDokumentPlacanjeDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnDokumentPlacanjeDataGridViewDataError);
			this.uxDokumentPlacanjeDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDokumentPlacanjeDataGridViewCellValueNeeded);
			this.uxDokumentPlacanjeDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDokumentPlacanjeDataGridViewCellValuePushed);
			
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = true;		
			//
			// uxIDDokumentDataGridViewColumn
			//
			this.uxIDDokumentDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDokumentDataGridViewColumn.DataPropertyName = "IDDokument";
			this.uxIDDokumentDataGridViewColumn.HeaderText = "IDDokument";
			this.uxIDDokumentDataGridViewColumn.Name = "uxIDDokumentDataGridViewColumn";
			this.uxIDDokumentDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDokumentDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDokumentDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDNacinPlacanjaDataGridViewColumn
			//
			this.uxIDNacinPlacanjaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDNacinPlacanjaDataGridViewColumn.DataPropertyName = "IDNacinPlacanja";
			this.uxIDNacinPlacanjaDataGridViewColumn.HeaderText = "IDNacinPlacanja";
			this.uxIDNacinPlacanjaDataGridViewColumn.Name = "uxIDNacinPlacanjaDataGridViewColumn";
			this.uxIDNacinPlacanjaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDNacinPlacanjaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDNacinPlacanjaDataGridViewColumn.ReadOnly = false;		
			//
			// uxUplacenoDataGridViewColumn
			//
			this.uxUplacenoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxUplacenoDataGridViewColumn.DataPropertyName = "Uplaceno";
			this.uxUplacenoDataGridViewColumn.HeaderText = "Uplaceno";
			this.uxUplacenoDataGridViewColumn.Name = "uxUplacenoDataGridViewColumn";
			this.uxUplacenoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxUplacenoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxUplacenoDataGridViewColumn.ReadOnly = false;		
			//
			// uxDatumDataGridViewColumn
			//
			this.uxDatumDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDatumDataGridViewColumn.DataPropertyName = "Datum";
			this.uxDatumDataGridViewColumn.HeaderText = "Datum";
			this.uxDatumDataGridViewColumn.Name = "uxDatumDataGridViewColumn";
			this.uxDatumDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDatumDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDatumDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDDokumentDataGridViewColumn
			//				
			this.uxIDDokumentDataGridViewColumn.DisplayMember = "IDDokumentTip";	
			this.uxIDDokumentDataGridViewColumn.ValueMember = "ID";	
			this.uxIDDokumentDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDDokumentDataGridViewColumn.DataSource = uxIDDokumentBindingSource;				
				
			//
			// uxIDNacinPlacanjaDataGridViewColumn
			//				
			this.uxIDNacinPlacanjaDataGridViewColumn.DisplayMember = "Naziv";	
			this.uxIDNacinPlacanjaDataGridViewColumn.ValueMember = "ID";	
			this.uxIDNacinPlacanjaDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDNacinPlacanjaDataGridViewColumn.DataSource = uxIDNacinPlacanjaBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxDokumentPlacanjeDataGridView);
			this.Name = "DokumentPlacanjeDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxIDNacinPlacanjaBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentPlacanjeErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentPlacanjeDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentPlacanjeBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				DokumentPlacanjeDataGridViewEventArgs args = new DokumentPlacanjeDataGridViewEventArgs();
				args.DokumentPlacanje = _currentDokumentPlacanje;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class DokumentPlacanjeDataGridViewEventArgs : System.EventArgs
		{
			private Entities.DokumentPlacanje	_DokumentPlacanje;
	
			/// <summary>
			/// the  Entities.DokumentPlacanje instance.
			/// </summary>
			public Entities.DokumentPlacanje DokumentPlacanje
			{
				get { return _DokumentPlacanje; }
				set { _DokumentPlacanje = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxDokumentPlacanjeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentPlacanjeDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxDokumentPlacanjeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentPlacanjeDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDokumentPlacanjeDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						e.Value = DokumentPlacanjeList[e.RowIndex].ID;
						break;
					case "uxIDDokumentDataGridViewColumn":
						e.Value = DokumentPlacanjeList[e.RowIndex].IDDokument;
						break;
					case "uxIDNacinPlacanjaDataGridViewColumn":
						e.Value = DokumentPlacanjeList[e.RowIndex].IDNacinPlacanja;
						break;
					case "uxUplacenoDataGridViewColumn":
						e.Value = DokumentPlacanjeList[e.RowIndex].Uplaceno;
						break;
					case "uxDatumDataGridViewColumn":
						e.Value = DokumentPlacanjeList[e.RowIndex].Datum;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxDokumentPlacanjeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentPlacanjeDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDokumentPlacanjeDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						DokumentPlacanjeList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
					case "uxIDDokumentDataGridViewColumn":
						DokumentPlacanjeList[e.RowIndex].IDDokument = (System.Int32)e.Value;
						break;
					case "uxIDNacinPlacanjaDataGridViewColumn":
						DokumentPlacanjeList[e.RowIndex].IDNacinPlacanja = (System.Int32)e.Value;
						break;
					case "uxUplacenoDataGridViewColumn":
						DokumentPlacanjeList[e.RowIndex].Uplaceno = (System.Decimal)e.Value;
						break;
					case "uxDatumDataGridViewColumn":
						DokumentPlacanjeList[e.RowIndex].Datum = (System.DateTime)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
